package com.yxb.profile.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yxb.common.annotation.Log;
import com.yxb.common.core.controller.BaseController;
import com.yxb.common.core.domain.AjaxResult;
import com.yxb.common.enums.BusinessType;
import com.yxb.profile.domain.TeacherProfile;
import com.yxb.profile.service.ITeacherProfileService;
import com.yxb.common.utils.poi.ExcelUtil;
import com.yxb.common.core.page.TableDataInfo;

/**
 * 教员信息Controller
 * 
 * @author 林德炫
 * @date 2025-03-28
 */
@RestController
@RequestMapping("/profile/profile")
public class TeacherProfileController extends BaseController
{
    @Autowired
    private ITeacherProfileService teacherProfileService;

    /**
     * 获取教员联系方式
     */
    @PreAuthorize("@ss.hasPermi('profile:profile:query')")
    @GetMapping(value = "getTeacherPhone/{userId}")
    public AjaxResult getTeacherPhone(@PathVariable("userId") Long userId)
    {
        return success(teacherProfileService.getTeacherPhone(userId));
    }

    /**
     * 查询教员信息列表
     */
    @PreAuthorize("@ss.hasPermi('profile:profile:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeacherProfile teacherProfile)
    {
        startPage();
        List<TeacherProfile> list = teacherProfileService.selectTeacherProfileList(teacherProfile);
        return getDataTable(list);
    }

    @GetMapping("/getTeacherListByCategoryId/{categoryId}")
    public List<TeacherProfile> getTeacherListByCategoryId(@PathVariable("categoryId") Long categoryId)
    {
        System.out.println("categoryId:"+categoryId);
        return teacherProfileService.getTeacherListByCategoryId(categoryId);
    }

    @GetMapping("/getTeacherDetailByTeacherId/{teacherId}")
    public TeacherProfile getTeacherDetailByTeacherId(@PathVariable("teacherId") String teacherId)
    {
        return teacherProfileService.getTeacherDetailByTeacherId(teacherId);
    }


    @GetMapping("/getTeacherList")
    public List<TeacherProfile> getTeacherList()
    {
        return teacherProfileService.getTeacherList();
    }

    /**
     * 导出教员信息列表
     */
    @PreAuthorize("@ss.hasPermi('profile:profile:export')")
    @Log(title = "教员信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeacherProfile teacherProfile)
    {
        List<TeacherProfile> list = teacherProfileService.selectTeacherProfileList(teacherProfile);
        ExcelUtil<TeacherProfile> util = new ExcelUtil<TeacherProfile>(TeacherProfile.class);
        util.exportExcel(response, list, "教员信息数据");
    }

    /**
     * 获取教员信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('profile:profile:query')")
    @GetMapping(value = "/{teacherId}")
    public AjaxResult getInfo(@PathVariable("teacherId") Long teacherId)
    {
        return success(teacherProfileService.selectTeacherProfileByTeacherId(teacherId));
    }

    /**
     * 新增教员信息
     */
    @PreAuthorize("@ss.hasPermi('profile:profile:add')")
    @Log(title = "教员信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeacherProfile teacherProfile)
    {
        return toAjax(teacherProfileService.insertTeacherProfile(teacherProfile));
    }

    /**
     * 修改教员信息
     */
    @PreAuthorize("@ss.hasPermi('profile:profile:edit')")
    @Log(title = "教员信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeacherProfile teacherProfile)
    {
        System.out.println(teacherProfile);
        return toAjax(teacherProfileService.updateTeacherProfile(teacherProfile));
    }

    /**
     * 删除教员信息
     */
    @PreAuthorize("@ss.hasPermi('profile:profile:remove')")
    @Log(title = "教员信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{teacherIds}")
    public AjaxResult remove(@PathVariable Long[] teacherIds)
    {
        return toAjax(teacherProfileService.deleteTeacherProfileByTeacherIds(teacherIds));
    }
}
